package com.yuantu.judiciary.serviceimpl;

import com.yuantu.judiciary.dao.ISysFeedbackDao;
import com.yuantu.judiciary.dao.IUserInfoDao;
import com.yuantu.judiciary.model.domain.SysFeedbackDO;
import com.yuantu.judiciary.model.dto.AccountInfoDTO;
import com.yuantu.judiciary.model.dto.SendComplaintDataDTO;
import com.yuantu.judiciary.model.enums.EndpointType;
import com.yuantu.judiciary.model.enums.SmsTemplateType;
import com.yuantu.judiciary.model.form.AddFeedbackForm;
import com.yuantu.judiciary.service.ISmsService;
import com.yuantu.judiciary.service.ISysFeedbackService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 反馈
 *
 * @author syw
 * @since 2023-08-17
 **/
@Service
@RequiredArgsConstructor
public class SysFeedbackServiceImpl implements ISysFeedbackService {

    private final ISysFeedbackDao feedbackDao;


    private final ISmsService smsService;

    private final IUserInfoDao userInfoDao;

    @Override
    public Boolean add(AddFeedbackForm form, AccountInfoDTO account) {
        SysFeedbackDO feedback = new SysFeedbackDO();
        feedback.setContent(form.getContent());
        feedback.setEndPoint(account.getEndpoint().toString());
        feedbackDao.save(feedback);
        //发送短信
        SendComplaintDataDTO sendComplaintData = new SendComplaintDataDTO();
        if (EndpointType.APPLET.equals(account.getEndpoint())) {
            sendComplaintData.setSource("诚信保微信小程序");
        } else if (EndpointType.ALIPAY_APPLET.equals(account.getEndpoint())) {
            sendComplaintData.setSource("诚信保支付宝小程序");
        }
        Long userId = account.getUserId();
        String phone = userInfoDao.findByIdAndDeletedFalse(userId).getPhone();
        sendComplaintData.setName(account.getUsername() + phone);
        sendComplaintData.setContent(form.getContent());
        smsService.sendMsgCode("18013928189", sendComplaintData, null, SmsTemplateType.COMPLAINT);
        return true;
    }

}
